/**
 * token模型
 *
 * Created by snowingsea on 2020/01/21.
 */
const mongoose = require('mongoose');
const schemaDefinition = require('./schema/token');
const schemaInstance = mongoose.Schema(schemaDefinition);
const { expiresIn } = global.config ? global.config.auth : {};
schemaInstance.index({ expires: 1 }, { expireAfterSeconds: expiresIn });

const modelInstance = mongoose.model('token', schemaInstance);
mongoose.connection.on('open', () => modelInstance.syncIndexes().catch(() => {}));

/**
 * Export model definition object.
 */
module.exports = modelInstance;
